#define  _CRT_SECURE_NO_WARNINGS
class Solution {
    vector<vector<int>> ret;
    vector<int> path;
    vector<bool> jug;
    void dfs(vector<int>& nums)
    {
        if (path.size() == nums.size())
        {
            ret.push_back(path);
            return;
        }
        for (int i = 0; i < nums.size(); i++)
        {
            if (jug[i])
            {
                while (i + 1 < nums.size() && jug[i + 1] && nums[i + 1] == nums[i]) i++;
                jug[i] = false;
                path.push_back(nums[i]);
                dfs(nums);
                jug[i] = true;
                path.pop_back();
            }
        }
    }
public:
    vector<vector<int>> permuteUnique(vector<int>& nums) {
        jug.resize(nums.size(), true);
        sort(nums.begin(), nums.end());
        dfs(nums);
        return ret;
    }
};